What is the most efficient way to duplicate (create a copy of, not a reference to) a Skip?
I assume I have no option but loop through and put each key:value to the new skip.
SystemAdmin - Wed Mar 02 06:17:50 EST 2011 |
|
Re: Duplicate a Skip SystemAdmin - Wed Mar 02 06:38:54 EST 2011
Here's what I've done. Since I don't know how to find out if a Skip was created with "create" or "createString" I have left that for the programmer outside the function. Can we find the create method out?
void CopySkip(Skip& Original, Skip& Duplicate)
{
setempty(Duplicate)
_y Data
for Data in Original do {
_x Key = key Original
put(Duplicate, Key, Data, true)
}
}
|
|
Re: Duplicate a Skip Mathias Mamsch - Wed Mar 02 10:22:34 EST 2011 SystemAdmin - Wed Mar 02 06:38:54 EST 2011
Here's what I've done. Since I don't know how to find out if a Skip was created with "create" or "createString" I have left that for the programmer outside the function. Can we find the create method out?
void CopySkip(Skip& Original, Skip& Duplicate)
{
setempty(Duplicate)
_y Data
for Data in Original do {
_x Key = key Original
put(Duplicate, Key, Data, true)
}
}
You can find out, by looking at the Skip structure memory, but I think you shouldn't for two reasons:
a) When a programmer has to decide on Skip List creation, what kind of skip list he is going to use (string or not string), he should also decide the same when he duplicates one. Because if he does not know what kind of data is in the skip list he is about to use, that will go wrong in most cases.
b) Whenever IBM decides to change its internal data structures, the code will break and produce hard to find errors. So unless you are absolutely about the platforms the code will run on, you should not use this.
Btw. I would make the parameters Skip duplicate (Skip sk, bool bString), that makes for a nicer calling syntax.
Regards, Mathias
bool isString (Skip sk) {
int &ref = addr_ ( ((addr_ sk) int) + 4)
int val = ref; return val != 0
}
Skip skNoString = create()
print "NoString: " (isString skNoString) "\n"
Skip skYahString = createString()
print "YahString: " (isString skYahString ) "\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
|
Re: Duplicate a Skip llandale - Wed Mar 02 15:05:59 EST 2011 Mathias Mamsch - Wed Mar 02 10:22:34 EST 2011
You can find out, by looking at the Skip structure memory, but I think you shouldn't for two reasons:
a) When a programmer has to decide on Skip List creation, what kind of skip list he is going to use (string or not string), he should also decide the same when he duplicates one. Because if he does not know what kind of data is in the skip list he is about to use, that will go wrong in most cases.
b) Whenever IBM decides to change its internal data structures, the code will break and produce hard to find errors. So unless you are absolutely about the platforms the code will run on, you should not use this.
Btw. I would make the parameters Skip duplicate (Skip sk, bool bString), that makes for a nicer calling syntax.
Regards, Mathias
bool isString (Skip sk) {
int &ref = addr_ ( ((addr_ sk) int) + 4)
int val = ref; return val != 0
}
Skip skNoString = create()
print "NoString: " (isString skNoString) "\n"
Skip skYahString = createString()
print "YahString: " (isString skYahString ) "\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
I would like to point out that the original Copy function of this thread only works for scalor Key and Data; will not work when the Data is a structure like an array or another Skip.
Agree with most of this, however I indeed have an skip list structure where Skip lists are embedded inside this other Skip list; and some of the embedded Skip lists are type String and other's are not. If I were to write a generic copy function, then we don't really know whether the embedded Skip is String or not, thus requireing your clever function to determine it.
If you are concerned about version changing you could, then I suppose, modify your function to be sensitive to the current DOORS version:
if (doorsInfo(infoVersion))0:1 == "9.") then Offset = 4
elseif(doorsInfo(infoVersion))0:3 == "10.") then Offset = 5
else Offset = 4
|
|
Re: Duplicate a Skip Mathias Mamsch - Wed Mar 02 16:47:52 EST 2011 llandale - Wed Mar 02 15:05:59 EST 2011
I would like to point out that the original Copy function of this thread only works for scalor Key and Data; will not work when the Data is a structure like an array or another Skip.
Agree with most of this, however I indeed have an skip list structure where Skip lists are embedded inside this other Skip list; and some of the embedded Skip lists are type String and other's are not. If I were to write a generic copy function, then we don't really know whether the embedded Skip is String or not, thus requireing your clever function to determine it.
If you are concerned about version changing you could, then I suppose, modify your function to be sensitive to the current DOORS version:
if (doorsInfo(infoVersion))0:1 == "9.") then Offset = 4
elseif(doorsInfo(infoVersion))0:3 == "10.") then Offset = 5
else Offset = 4
If you say "only works for scalar key and data" you mean that the key and values (if they are arrays, etc.) are not duplicated, but referenced in the new skip list, right? The function still works, however it does not do a deep-copy (a programmer might expect).
I am very much afraid of skip lists that contain inhomogenous key / value types. Imagining a skip where you have other Skip lists embedded, sometimes string-skips, sometimes not. I really wonder how a programmer is supposed to work with it without crashing DOORS (regardless of the reasons for duplicating this skip). Maybe a very clever "type deduction" from the keys (odd key = string skip, even key = non string skip), but that seems very error prone to me. Would we really want to support that stuff by introducing a isString (Skip) function ;-)
Regarding compatibility: Nice idea, storing the offsets version dependent. In some cases if the internal data structures change completely one could even recode the complete function like isStringDOORS8, isStringDOORS10. Shall we do an "DOORS Internal Data Structure" wiki?
Regards, Mathias
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
|
Re: Duplicate a Skip SystemAdmin - Thu Mar 03 07:47:01 EST 2011 llandale - Wed Mar 02 15:05:59 EST 2011
I would like to point out that the original Copy function of this thread only works for scalor Key and Data; will not work when the Data is a structure like an array or another Skip.
Agree with most of this, however I indeed have an skip list structure where Skip lists are embedded inside this other Skip list; and some of the embedded Skip lists are type String and other's are not. If I were to write a generic copy function, then we don't really know whether the embedded Skip is String or not, thus requireing your clever function to determine it.
If you are concerned about version changing you could, then I suppose, modify your function to be sensitive to the current DOORS version:
if (doorsInfo(infoVersion))0:1 == "9.") then Offset = 4
elseif(doorsInfo(infoVersion))0:3 == "10.") then Offset = 5
else Offset = 4
Yes, I am aware that some data types will be references - I want that!. I'm not really concerned that the data is the same referenced object for both Skips, rather that deleting/adding keys to the copied Skip doesn't change the original. Essentially I am returning a Skip from a custom type to be looped through without danger of modifying the internals of the custom type. This stems from being unable to override the iterators as disscussed here - https://www.ibm.com/developerworks/forums/thread.jspa?threadID=362340&tstart=0
The original function or similar (+Skip duplicate (Skip sk, bool bString)+) is fine for this purpose.
|
|